import re
import requests

url = 'https://www.lmonkey.com/ask'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
}

res = requests.get(url=url, headers=headers)
if res.status_code == 200:
    html=res.text
    # 定义解析标题的正则
    # <div class="topic_title mb-0 lh-180 ml-n2">【Python】源码哪里有<small class="float-right text-muted" data-toggle="tooltip" data-placement="top" title="" data-original-title="0个回复"><i class="fa fas fa-comments"></i>&nbsp;0</small></div>
    regtitle = '<div class="topic_title mb-0 lh-180 ml-n2">(.*?)<small'
    titles = re.findall(regtitle, html)
    # 定义解析作者的正则
    '''<p class="lh-140 mb-0 topic_info">
                                &nbsp; •& nbsp;
                <strong>孫小兜</strong>
                &nbsp;•&nbsp;
                <span data-toggle="tooltip" data-placement="top" title="" data-original-title="2020-05-08 16:36:02">
                                                1天前
                                            </span>
                &nbsp;•&nbsp;
                <i class="fa fa-thumbs-up" data-toggle="tooltip" data-placement="top" title="" data-original-title="获得0个赞"></i> 0
                    &nbsp;•&nbsp;
                    <i class="fa fa-eye" data-toggle="tooltip" data-placement="top" title="" data-original-title="查看数2"></i> 2
        </p>'''
    regauthor='<strong>(.*?)</strong>'
    authors = re.findall(regauthor, html)
    print(authors)
    regdate='<span data-toggle="tooltip" data-placement="top" title="(.*?)">'
    dates=re.findall(regdate,html)

    articles=zip(titles,authors,dates)
    print(*articles)
